package cn.edu.sjtu.stap.cg.builder;

import java.util.*;

import org.aspectj.asm.*;
import org.aspectj.org.eclipse.jdt.internal.compiler.ast.*;

import cn.edu.sjtu.stap.cg.*;
import cn.edu.sjtu.stap.hg.*;

/**
 * Interface of CG builders. It provides a sequence of methods for the
 * construction of CGs. It also provides methods to initialize the builder and
 * get the results after construction.
 * 
 * @author William
 * 
 */
public interface ICgBuilder {
    /**
     * Initialization of this builder.
     * 
     */
    public void initialize();

    /**
     * Build CGs for the given AST (<code>unit</code>) with the help of
     * hierarchy graph. It builds object-oriented(OO) CGs for each AST, that is
     * to say it covers the features of OO without considering the
     * aspect-oriented(AO) features. This is the first phase of CG construction.
     * 
     * @param hg
     *            the Hierarchy Graph(HG) that provides the hierarchy
     *            information of types.
     * @param unit
     *            the AST to build CG for.
     */
    public void buildCallGraph(HierarchyGraph hg, CompilationUnitDeclaration unit);

    /**
     * Update the object-oriented CGs by adding aspect-oriented features. The
     * match information of advices and methods are provided by the given ASM
     * manager. With the information in ASM manager, the implicit calls from
     * methods to advices are also added into the call graph to provide complete
     * invocation information. This is the second phase of CG construction.
     * 
     * @param manager
     *            the AsmManager that provide the method-advice matching
     *            information.
     */
    public void buildCallGraph(AsmManager manager);

    /**
     * Get the results after CG construction.
     * 
     * @return Map of CGs for each module.
     */
    public Map<AbstractMethodDeclaration, CallGraph> getResult();

    /**
     * Get the program entries. A program entry is a method that takes the
     * following signature: <code>public static void main(String[])</code>,
     * which is usually the main method of a program.
     * 
     * @return Set of the main method declarations.
     */
    public Set<AbstractMethodDeclaration> getProgramEntries();
}
